package org.flashbrighton.as3bots.views
{
	import flash.display.BlendMode;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.*;
	
	import org.flashbrighton.as3bots.models.BotModel;

	public class BotGraphic extends Sprite
	{
		[Embed(source="C:\\WINDOWS\\Fonts\\arial.ttf", fontFamily="Arial")]
		private var _arial:String;
		
		private var _model:BotModel;
		private var _damageLevel:Shape;
		
		public function BotGraphic(model:BotModel)
		{
			_model = model;
			draw();
			drawDamageLevel();
			drawLabel();
		}
		
		public function get model():BotModel
		{
			return _model;
		}
		
		
		public function update():void
		{
			_damageLevel.scaleX = _damageLevel.scaleY = Math.min(1, 1 - (_model.energy / 1000));
		}
		
		
		private function draw():void
		{
			var circle:Shape = new Shape();
			var g:Graphics = circle.graphics;
			
			g.lineStyle(2, 0x000000);
			g.beginFill(_model.colour);
			g.drawCircle(0, 0, 100);
			g.endFill();
			g.moveTo(0, 0);
			g.lineTo(100, 0);
			addChild(circle);
		}
		
		
		private function drawDamageLevel():void
		{
			_damageLevel = new Shape();
			var g:Graphics = _damageLevel.graphics;
			g.beginFill(0x000000);
			g.drawCircle(0, 0, 100);
			g.endFill();
			addChild(_damageLevel);
			_damageLevel.scaleX = _damageLevel.scaleY = 0;
		}
		
		
		private function drawLabel():void
		{
			var label:TextField = new TextField();
			label.embedFonts = true;
			label.defaultTextFormat = new TextFormat("Arial", 30, 0xFFFFFF);
			label.text = _model.name;
			label.blendMode = BlendMode.DIFFERENCE;
			addChild(label);
		}
	}
}